#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   user_schemas.py
@Time    :   2021/02/06 12:39:10
@Author  :   superjin
@Version :   1.0
'''

from typing import Optional,List
from datetime import datetime
from uuid import UUID
from pydantic import BaseModel, EmailStr, AnyHttpUrl, validator, Field 
from core.schemas.base import BaseResponse

class Token(BaseModel):
    access_token: str
    token_type: str
    expire_at: datetime

        
# 创建账号需要验证的条件
class UserCreate(BaseModel):
    username: Optional[str]
    name: str
    role: str
    email: Optional[EmailStr]
    phone: Optional[str]
    password: str

    @validator('password')
    def check_password(cls, v):
        if len(v) < 8:
            raise ValueError('password too short')
        return v


class ChangeUserPassword(BaseModel):
    password: str 
    @validator('password')
    def check_password(cls, v):
        if len(v) < 8:
            raise ValueError('password to short')
        return v

class UserOut(BaseModel):
    pass

class UserProfile(BaseModel):
    user_id: int
    username: Optional[str]
    name: str
    email: Optional[EmailStr]
    phone: Optional[str]
    role:str
    pic_url: Optional[str]
    class_id:int

class UserUpdate(BaseModel):
    username: Optional[str]
    name: Optional[str]
    email: Optional[EmailStr]
    phone: Optional[str]

class UserOutResponse(BaseResponse):
    data:UserProfile

class UserList(BaseModel):
    users: List[UserOut]
    total: int

class UserListResponse(BaseResponse):
    data:UserList

